import { useMemo } from "react";
import { useAppSelector } from "../app/hooks";

export function useCar() {
  const car = useAppSelector((state) => state.car.data);

  const price = useMemo(() => {
    return car.reduce((p, n) => {
      return n.isChecked ? p + n.price * n.count : p;
    }, 0);
  }, [car]);

	const allCheck = useMemo(() => {
    return car.every((v) => {
      return v.isChecked
    });
  }, [car]);

  return {
    price,
		allCheck
  };
}
